package com.CuiChangHe.studentmanager.service.studentdetailedinfo.impl;

import com.CuiChangHe.studentmanager.dao.StudentInfoDao;
import com.CuiChangHe.studentmanager.entity.studentdetailedinfo.StudentDetailedInfoData;
import com.CuiChangHe.studentmanager.entity.studentdetailedinfo.StudentDetailedInfoReturnMsg;
import com.CuiChangHe.studentmanager.mapper.StudentDetailedInfoMapper;
import com.CuiChangHe.studentmanager.service.studentdetailedinfo.StudentDetailedInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * @Description :学生详细信息业务实现
 * @Author :崔昌赫
 * @Date : 2021/11/18
 */
@Service
@Slf4j
public class StudentDetailedInfoServiceImpl implements StudentDetailedInfoService {

    private StudentDetailedInfoMapper mapper;

    @Autowired
    public void setMapper(StudentDetailedInfoMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    @Transactional(readOnly = true)
    public StudentDetailedInfoReturnMsg findStudentDetailedInfoByStudentId(String studentid) {
        StudentDetailedInfoReturnMsg returnMsg = new StudentDetailedInfoReturnMsg();
        log.info("开始通过学号查找学生详细信息.学号:{}",studentid);
        if (studentid==null || studentid.equals("")){
            log.warn("检测到学号为空！");
            returnMsg.setCode(50000);
            returnMsg.setMessage("检测到学号为空!");
            return returnMsg;
        }
        StudentInfoDao[] studentDetailedInfoByStudentId = mapper.findStudentDetailedInfoByStudentId(studentid);
        if(studentDetailedInfoByStudentId.length==0){
            log.warn("未能找到该学生的详细信息!学号:{}",studentid);
            returnMsg.setCode(50000);
            returnMsg.setMessage("未能找到该学生的详细信息!");
            return returnMsg;
        }
        log.info("查找结果为:{}", Arrays.toString(studentDetailedInfoByStudentId));
        returnMsg.setData(new StudentDetailedInfoData(studentDetailedInfoByStudentId.length, studentDetailedInfoByStudentId));
        returnMsg.setCode(20000);
        returnMsg.setMessage("查找成功!");
        log.info("查找成功!本次业务结束.");
        return returnMsg;
    }
}
